package com.bdqn.wang.dao.impl;

import cn.hutool.db.Page;
import com.bdqn.wang.dao.ComdityDao;
import com.bdqn.wang.pojo.Comdity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ComdityDaoImpl extends BaseDao implements ComdityDao {
    @Override
    public List<Comdity> getAll() {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            connection = getConnection();
            String sql = "select * from easybuy_product_category where shanchu=0";
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
            List<Comdity> comdityList = new ArrayList<Comdity>();
            while (resultSet.next()){
                Comdity comdity = new Comdity();
                comdity.setId(resultSet.getInt(1));
                comdity.setName(resultSet.getString(2));
                comdity.setType(resultSet.getInt(3));
                comdity.setParentId(resultSet.getInt(4));
                comdityList.add(comdity);
            }
            return comdityList;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            closeAll(resultSet,preparedStatement,connection);
        }

        return null;
    }



    @Override
    public int del(int id) {
        String sql="update easybuy_product_category set shanchu = 1 where id = ?";
        Object [] obj = {id};
        return executeUpdate(sql,obj);
    }

    @Override
    public int add(Comdity comdity) {
        String sql = "insert into easybuy_product_category values(default,?,?,?,?,default)";
        Object[] obj = {
                comdity.getName(),
                comdity.getParentId(),
                comdity.getType(),
                comdity.getIconClass()
        };
        return executeUpdate(sql,obj);
    }

    @Override
    public List<Comdity> getAllThree() {
        return null;
    }

    @Override
    public List<Comdity> getAll(int tow) {
        return null;
    }


}
